import logging
import time

from util.db import DBManager
from util.web.api_session import APISessionHandler


class MyAPIHandler(APISessionHandler):
    def initialize(self, api_package, business):
        super(MyAPIHandler, self).initialize(api_package)
        self.business = business

    def call_api(self, api_path, args):
        t = time.time()
        args['business'] = self.business
        args['db_manager'] = self.business.db_manager
        # if api_path not in ('user/login', 'user/current') and not hasattr(self.get_session(), 'user'):
        #     raise ErrException(1, '用户没有登录')
        result = super(MyAPIHandler, self).call_api(api_path, args)
        t = time.time() - t
        logging.getLogger().info('process api %s, in %.4f milliscondes' % (api_path, t*1000))
        return result
